﻿using System;
using ExtraClub.Domain;
using ExtraClub.Domain.Entities;
using SubSonic;
using System.Collections.Generic;
using ExtraClub.Domain.Forms;

namespace ExtraClub.Web.Forms.client_filter {
    public partial class module : BaseForm {
        protected Club SelectedEntity { get; set; }

        protected override void OnLoad(EventArgs e) {
            if (Request.QueryString.Count > 0 && Request.QueryString["id"] != null) {
                SelectedEntity = Club.FetchByID(int.Parse(Request.QueryString["id"]));
            }

            base.OnLoad(e);
        }

        protected override string SetFields() {
            string ret = "null";
            switch (CurrentCommand) {
                case ECommand.Filter:
                    ret = BuildFilterForm();
                    break;
            }
            return ret;
        }

        private string BuildFilterForm() {
            FieldCollection fs = new FieldCollection();
            AddHiddenFieldes(ref fs, SelectedEntity != null ? SelectedEntity.Id.ToString() : "");

            /* First Name */
            Field firstName = new Field(FieldType.String);
            firstName.Label = UIText["first-name-label"];
            firstName.CodeName = Client.Columns.FirstName.ToLower();
            firstName.Size = Client.Schema.GetColumn(Client.Columns.FirstName).MaxLength;
            firstName.Required = true;
            fs.Add(firstName.ToJSON());

            return fs.JSON();

        }
    }
}
